<template>
  <div class="main">
    <div class="headcard" style="min-height: 100vh; height: 100%">
      <div class="uc-header">
        <div class="back" @click="$router.back()">
          <img src="@/assets/img/3.png" />
        </div>
        <div class="title">{{ $t("NumberOfDiamonds") }}</div>
        <div class="head-tips" @click="$router.push('/rechargeHistory')">
          <img src="@/assets/img/18.png" />
        </div>
      </div>
      <div class="shop-box">
        <div class="shop-header">
          <!-- <div>
            <img src="@/assets/img/diamondd.png" alt="" class="diamondd" />
          </div> -->
          <div>{{ formatMoney(assets_total, true) }} {{ $t("USD") }}</div>
        </div>
        <van-list
          class="shop-content"
          v-model="listLoading"
          @load="onLoadList"
          :finished="this.list.length == this.pages.total"
        >
          <div class="nodata" v-show="pages.nodata">
            <img src="@/assets/img/default.jpg" />
            <p>No data</p>
          </div>
          <div
            class="shop-items"
            v-for="v in list"
            :key="v.id"
            @click="goPay(v)"
          >
            <!-- <div class="shop-items-tip">{{ v.tip }}</div> -->
            <div
              class="shop-item"
              :style="v.checked ? 'background: #aab6e8' : ''"
            >
              <!-- <div class="shop-item-body">
                <img :src="v.big_icon" class="big_icon" />
                <div class="shop-item-amount">
                  <img :src="v.small_icon" alt="" />
                  <span>{{ v.amount }}</span>
                </div>
              </div> -->
              <!-- <div class="shop-item-money"> -->
              {{ v.currency_symbol }} {{ v.price }}
              <!-- </div> -->
            </div>
          </div>
        </van-list>
      </div>
      <div class="textContent">
        <p v-html="goods_tip"></p>
      </div>
    </div>
  </div>
</template>

<script>
import { httpGetChannel, httpInfo, httpGoodsList } from "@/http/api";
import { formatMoney } from "@/utils/common";

export default {
  name: "recharge",
  data() {
    return {
      value: 0,
      listLoading: false,
      ways2: [], // 默认支付方式
      selectItem: {}, // 选中的支付方式
      deleModal: false, // 删除弹窗是否展示
      paysAjax: false,
      assets_total: 0,
      disabled: true,
      list: [],
      goods_tip: "",
      pages: {
        // 分页信息
        page: 1,
        total: 0,
        nodata: false,
      },
    };
  },
  created() {
    this.getHttpGetChannel();
    this.getHttpGoodsList();
    this.getHttpInfo();
  },
  methods: {
    formatMoney,
    goPay(item) {
      this.$router.push({
        path: "/orderWay",
        query: {
          item: JSON.stringify(item),
        },
      });
    },
    async getHttpInfo() {
      let res = await httpInfo();
      if (res.code == 0) {
        this.assets_total = res.data?.diamond || 0;
      }
    },
    async getHttpGoodsList() {
      let params = {
        page: this.pages.page,
      };
      const res = await httpGoodsList(params);
      if (res.code == 0) {
        this.list = [...this.list, ...(res.data.list || [])];
        this.goods_tip = res.data?.goods_tip.replace(/\n/g, "<br/>");
        this.pages.total = res.data.page.total_count;
        if (this.list.length < this.pages.total) this.pages.page++;
        if (!this.pages.total) this.pages.nodata = true;
      }
      this.listLoading = false;
    },
    // 获取支付通道
    async getHttpGetChannel() {
      let res = await httpGetChannel();
      if (res.code == 0) {
        let arr = res.data || [];
        arr.forEach((v, i) => {
          v.key = `ways2${i}`;
        });
        this.ways2 = arr;
        if (this.ways2.length) {
          this.setSelectItem(res.data[0], 0, `ways2${0}`);
        }
      }
    },
    onLoadList() {
      this.listLoading = true;
      if (this.pages.nodata) return (this.listLoading = false);
      if (this.list.length == this.pages.total && this.pages.total > 0)
        return (this.listLoading = false);
      this.getHttpGoodsList();
    },
    // 选择支付方式
    setSelectItem(item) {
      this.selectItem = item;
    },
    // 删除历史支付方式
    delSelect() {
      this.deleModal = true;
    },
  },
};
</script>
<style lang="less" scoped>
@import url("./acc.less");
@import url("./newFont.less");

* {
  font-weight: 400;
  color: #93653e;
}

.diamondd {
  width: 40px;
  height: 40px;
}
.shop-box {
  width: 100%;
  .btn {
    margin: 0 auto;
    margin-top: 40px;
    width: 682px;
    height: 116px;
    background: linear-gradient(
      178.44deg,
      rgba(238, 220, 201, 1) 0%,
      rgba(220, 188, 155, 1) 100%
    );
    box-shadow: 1px 7px 8px 0px rgba(201, 173, 144, 0.51);
    font-size: 28px;
    font-weight: 400;
    letter-spacing: 0px;
    color: rgba(255, 255, 255, 1);
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 20px;
    // transition: all 0.05s;
    user-select: none;

    &:active {
      transform: translateY(2px);
    }

    &.disabled {
      background: #ccc;
      box-shadow: 1px 7px 8px 0px rgba(201, 173, 144, 0);
    }
  }
  .shop-header {
    background: linear-gradient(
      139.72deg,
      #e5c184 0%,
      #e5c184 47.16%,
      #e5c184 76.71%,
      #e5c184 100%
    );
    // background: linear-gradient(
    //   139.72deg,
    //   #e6e9ff 0%,
    //   #ced4f8 47.16%,
    //   #bfc8f2 76.71%,
    //   #aab6e8 100%
    // );
    display: flex;
    // justify-content: space-between;
    justify-content: center;
    padding: 20px;
    margin: 30px;
    border-radius: 15px;
    color: #8490b1;
  }
  .shop-content {
    display: flex;
    flex-wrap: wrap;
    .shop-items {
      width: 44%;
      margin-left: 30px;
      position: relative;
      .shop-items-tip {
        width: 180px;
        height: 40px;
        line-height: 1.5;
        background: #dd0d1f;
        position: absolute;
        right: 0.4vw;
        top: 2vw;
        // top: 65px;
        // transform: rotateZ(45deg);
        text-align: center;
        color: #fff;
        font-size: 16px;
        font-weight: 600;
      }
      .shop-item {
        width: 100%;
        // height: 400px;
        height: 71px;
        margin: 10px 0px;
        // padding: 40px 20px;
        box-sizing: border-box;
        // background: #ced4f8;
        background-color: #e5c184;
        border-radius: 15px;
        display: flex;
        align-items: center;
        justify-content: center;
        padding-bottom: 8px;
        font-size: 28px;
        .shop-item-body {
          text-align: center;
          width: 100%;
          height: 250px;
          border-radius: 15px;
          box-sizing: border-box;
          // background: #bfc8f2;
          background: #e1dbcf;
          padding-top: 10px;
          box-sizing: border-box;
          .big_icon {
            width: 200px;
            height: 180px;
          }
          .shop-item-amount {
            // color: #ffffff;
            display: flex;
            align-items: center;
            justify-content: center;

            color: rgba(255, 255, 255, 1);
            img {
              width: 70px;
              height: 40px;
              display: inline-block;
            }
          }
        }
        .shop-item-money {
          margin-top: 25px;
          font-size: 28px;
          // font-weight: 400;
          letter-spacing: 2.24px;
          color: #ffffff;
          // color: rgba(255, 255, 255, 1);
          width: 100%;
          height: 71px;
          // background: url("~@/assets/img/ucenter-info-t3.png") center/100% 71px no-repeat;
          background: url("~@/assets/img/19.png") center/100% 71px no-repeat;
          display: flex;
          align-items: center;
          justify-content: center;
          padding-bottom: 8px;
        }
      }
    }
  }
}
.paypopup {
  width: 100%;
  padding: 32px;

  .maskTitle {
    color: #cbcacd;
    font-size: 34px;
  }

  .amount-box {
    background-color: #f0f0f0;
    border-radius: 8px;
    margin: 20px 0;
    box-sizing: border-box;
    display: flex;
    align-content: center;
    justify-content: center;
    font-size: 60px;
    color: #333;
    padding: 30px;
    background: #f1f1f1;
    background: -moz-linear-gradient(#dcdcdc, #ffffff);
    background: -o-linear-gradient(#dcdcdc, #ffffff);
    background: -webkit-gradient(
      linear,
      0% 0%,
      0% 100%,
      from(#dcdcdc),
      to(#ffffff)
    );
    background: -webkit-linear-gradient(#dcdcdc, #ffffff);

    span {
      margin: 0 10px;
    }
  }

  .used-box {
    border-right: 1px solid #eee;
    margin-right: 10px;
  }

  .used-box-title {
    display: inline-block;
    font-size: 30px;
    height: 60px;
    color: #7aa2ee;
    flex-shrink: 0;
  }

  .more-box-title {
    display: flex;
    justify-content: space-between;
    align-items: stretch;

    span {
      font-size: 30px;
      height: 60px;
      color: #9a9a9c;
    }
  }

  .types {
    display: flex;
    margin-top: 10px;
    width: 100%;
    overflow-x: auto;

    .types-box {
      display: flex;
      margin-top: 10px;
    }

    .typeList {
      background: #f0f0f0;
      border-radius: 20px;
      padding: 30px 40px 24px 40px;
      box-sizing: border-box;
      margin-right: 20px;
      text-align: center;

      &.active {
        background: #c3daff;
      }

      img {
        width: 88px;
        height: 88px;
        margin: 0 auto;
      }

      p {
        font-size: 26px;
        color: #333;
        font-weight: 500;
        text-align: center;
        margin-top: 20px;
      }
    }
  }

  .suh {
    background: linear-gradient(90deg, rgb(80, 109, 231), rgb(63, 144, 242));
    box-shadow: 0px 0px 10px 0px rgba(68, 133, 239, 0.5);
    user-select: none;
    height: 80px;
    text-align: center;
    line-height: 80px;
    width: 600px;
    margin: 78px auto 40px;
    border-radius: 40px;
    font-size: 32px;
    color: #fff;
  }
}
.textContent {
  color: #fff;
  font-size: 24px;
  padding: 32px;
  > p {
    color: #fff;
  }
}
</style>
